package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.WxNotice;
import com.ruoyi.business.service.IWxNoticeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微信通知公告Controller
 * 
 * @author asher
 * @date 2021-11-12
 */
@RestController
@RequestMapping("/business/wx_notice")
public class WxNoticeController extends BaseController
{
    @Autowired
    private IWxNoticeService wxNoticeService;

    /**
     * 查询微信通知公告列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WxNotice wxNotice)
    {
        startPage();
        List<WxNotice> list = wxNoticeService.selectWxNoticeList(wxNotice);
        return getDataTable(list);
    }

    /**
     * 导出微信通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('business:wx_notice:export')")
    @Log(title = "微信通知公告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WxNotice wxNotice)
    {
        List<WxNotice> list = wxNoticeService.selectWxNoticeList(wxNotice);
        ExcelUtil<WxNotice> util = new ExcelUtil<WxNotice>(WxNotice.class);
        return util.exportExcel(list, "微信通知公告数据");
    }

    /**
     * 获取微信通知公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:wx_notice:query')")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") Integer noticeId)
    {
        return AjaxResult.success(wxNoticeService.selectWxNoticeByNoticeId(noticeId));
    }

    /**
     * 新增微信通知公告
     */
    @PreAuthorize("@ss.hasPermi('business:wx_notice:add')")
    @Log(title = "微信通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxNotice wxNotice)
    {
        return toAjax(wxNoticeService.insertWxNotice(wxNotice));
    }

    /**
     * 修改微信通知公告
     */
    @PreAuthorize("@ss.hasPermi('business:wx_notice:edit')")
    @Log(title = "微信通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxNotice wxNotice)
    {
        return toAjax(wxNoticeService.updateWxNotice(wxNotice));
    }

    /**
     * 删除微信通知公告
     */
    @PreAuthorize("@ss.hasPermi('business:wx_notice:remove')")
    @Log(title = "微信通知公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable Integer[] noticeIds)
    {
        return toAjax(wxNoticeService.deleteWxNoticeByNoticeIds(noticeIds));
    }
}
